<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
  //经典面试题：实现add(1)(2)(3)(4)=10;add(1)(1,2,3)(2)=9
  //指的是将一个接受多个参数的函数，变为接受一个参数返回一个函数的固定形式
  //这样便于再次调用，例如f(1)(2)
  function add() {
    let args = Array.from(arguments)
    let adder = function() {
      args.push(...arguments)
      return adder
    }
    adder.toString = function() {
      return args.reduce(function(a, b){
        return a + b
      }, 0)
    }
    return adder
  }
  let a = add(1,2,3)
  let b = add(1)(2)(3)
  console.log(a)
  console.log(b)
  console.log(a==6)
  console.log(b==6)
</script>
</html>
